<template>
  <div class="colorControl">
    <div class="control-head" v-if="showControlHeader">
      <p class="section-name">{{ title }}</p>
      <p class="reset" @click="resetColor">重置</p>
    </div>
    <div class="color-control">
      <a-input type="color" :value="color" @change="change" />
      <a-input
        type="text"
        style="width: 172px; height: 40px"
        :value="color"
        @change="change"
      />
    </div>
  </div>
</template>

<script>
export default {
  name: "colorControl",
  components: {},
  props: {
    color: {
      type: String,
      default: () => {
        return "";
      },
    },
    title: {
      type: String,
      default: "选择颜色",
    },
    showControlHeader: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {};
  },
  watch: {},
  computed: {},
  methods: {
    // 点击重置颜色
    resetColor() {
      this.$emit("reset");
    },
    change(e) {
      this.$emit("change", e.target.value);
    },
  },
};
</script>

<style lang="scss" scoped>
.colorControl {
  .control-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 0 12px 0;
    font-size: 12px;
    font-weight: 400;
    color: #000000;
    .reset {
      font-size: 12px;
      font-weight: 400;
      color: #8e8e8e;
      cursor: pointer;
      user-select: none;
    }
    p {
      margin: 0;
    }
  }
}
.color-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  input {
    border: 0 none;
    height: 100%;
    background: #f6f7f9;
    padding-top: 0;
    padding-bottom: 0;
    outline: none;
  }
  .ant-input {
    width: 48px;
    height: 40px;
    padding: 6px 12px;
  }
  span {
    flex: auto;
    height: 40px;
    border-radius: 4px;
    line-height: 40px;
    padding: 0 10px;
    background-color: #f6f7f9;
    margin-left: 10px;
  }
}
</style>
